package ru.spb.osll.myfit.server.parser;

import org.junit.Test;
import ru.spb.osll.myfit.common.Content;
import ru.spb.osll.myfit.common.PageElement;

import static org.junit.Assert.*;

/**
 * Created by IntelliJ IDEA.
 * User: Vassar
 * Date: 24.03.2011
 * Time: 13:15:10
 * To change this template use File | Settings | File Templates.
 */
public class ContentElementParserTest {
  private ContentElementParser contentParser = new ContentElementParser();

  @Test
  public void testValideContent(){
    String line = "!contents -R2";
    assertTrue(contentParser.matches(line));

    PageElement element = contentParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Content);

    assertEquals("2", ((Content)element).getLevel().toString());
  }

  @Test
  public void testValideAllContent(){
    String line = "!contents -R";
    assertTrue(contentParser.matches(line));

    PageElement element = contentParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Content);
    
    assertNull(((Content)element).getLevel());
  }

  @Test
  public void testNoLevelsContent(){
    String line = "!contents -RQ";
    assertFalse(contentParser.matches(line));
  }

  @Test
  public void testContentWithWhiteSpaceCharacters(){
    String line = "!contents          -R5         ";
    assertTrue(contentParser.matches(line));

    PageElement element = contentParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Content);

    assertEquals("5", ((Content)element).getLevel().toString());
  }


}
